const express= require('express')
const bodyParser=require('body-parser');
const fs=require('fs')
const app = express()
const router = express.Router();
app.use(router)//引入路由
router.use(bodyParser.urlencoded({extended:false}))
app.use(express.static('./static'))

router.get('/msg',(req,res)=>{
    let id=req.query.id
    res.sendFile(__dirname+'/data/'+id+'.json')
})
router.post('/msg',(req,res)=>{
    let data=req.body.newMsg
    fs.writeFile(__dirname+'/data/1.json',data,()=>{
        res.send('success');
    })
    
    
})
app.listen(8080)
